# 必须以管理员身份运行此脚本！
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator"))
{
    Write-Host "请以管理员身份运行此脚本！" -ForegroundColor Red
    exit
}

# 设置环境变量
[System.Environment]::SetEnvironmentVariable("PGSQL_IP", "localhost", "Machine")
[System.Environment]::SetEnvironmentVariable("PGSQL_PORT", "5432", "Machine")
[System.Environment]::SetEnvironmentVariable("PGSQL_DB", "your_database", "Machine")
[System.Environment]::SetEnvironmentVariable("PGSQL_USER_NAME", "your_username", "Machine")
[System.Environment]::SetEnvironmentVariable("PGSQL_USER_PASS", "your_password", "Machine")

# 输出结果验证
Write-Host "以下环境变量已设置为系统变量：" -ForegroundColor Green
Write-Host "PGSQL_IP: $env:PGSQL_IP"
Write-Host "PGSQL_PORT: $env:PGSQL_PORT"
Write-Host "PGSQL_DB: $env:PGSQL_DB"
Write-Host "PGSQL_USER_NAME: $env:PGSQL_USER_NAME"
Write-Host "PGSQL_USER_PASS: [安全隐藏]"

# 提示生效需重启
Write-Host "`n注意：新打开的终端或应用程序才能读取这些变量。" -ForegroundColor Yellow
Write-Host "按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")